"""capture class"""
import cv2


class CaptureInterface(object):
    """base class of capture"""
    def start(self):
        """start"""
        raise NotImplementedError

    def stop(self):
        """stop"""
        raise NotImplementedError

    def getType(self):
        """getType"""
        raise NotImplementedError

    def getFrame(self):
        """getFrame"""
        raise NotImplementedError

    def run(self):
        """run"""
        raise NotImplementedError


class USBCamera(CaptureInterface):
    """usb cam wrapper"""
    def __init__(self, dev, type_='usb_camera', size=[928,800]):
        """init"""
        self.dev_type = type_
        self.dev_name = dev
        self.size = size
        # dev_ = int(dev.split("/")[-1][5:])
        dev_ = dev
        self.cap = cv2.VideoCapture(dev_)
        self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, self.size[0])
        self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, self.size[1])

    def start(self):
        """start"""
        self.cap = cv2.VideoCapture(self.dev_name)
        self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, self.size[0])
        self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, self.size[1])
        if self.cap is None:
            return -1
        return 0

    def stop(self):
        """stop"""
        self.cap.release()
        return 0

    def getFrame(self):
        """getFrame"""
        _, frame = self.cap.read()
        return frame

    def getType(self):
        """getType"""
        return self.dev_type


